//
//  ShortcutView.m
//  自定义快捷回复
//
//  Created by zl on 2019/9/26.
//  Copyright © 2019 zl. All rights reserved.
//

#import "ShortcutView.h"

@implementation ShortcutView

- (UISegmentedControl *)segment{
    if (!_segment) {
        _segment = [[UISegmentedControl alloc]initWithItems:@[@"公共",@"个人"]];
        [_segment addTarget:self action:@selector(selectItem:) forControlEvents:UIControlEventValueChanged];
        _segment.selectedSegmentIndex = 0;
        _segment.backgroundColor = [UIColor colorWithHexString:@"#D9D9D9"];
        // 去掉颜色,现在整个segment偶看不到,可以相应点击事件
        _segment.tintColor = [UIColor colorWithHexString:@"#00DAAF"];
        _segment.layer.borderWidth = 3;
        _segment.layer.borderColor = [UIColor colorWithHexString:@"#F6F6F6"].CGColor;
        // 正常状态下
        NSDictionary * normalTextAttributes = @{NSFontAttributeName : [UIFont systemFontOfSize:13.0f],NSForegroundColorAttributeName : [UIColor grayColor]};
        [_segment setTitleTextAttributes:normalTextAttributes forState:UIControlStateNormal];
        
        // 选中状态下
        NSDictionary * selctedTextAttributes = @{NSFontAttributeName : [UIFont boldSystemFontOfSize:13.0f],NSForegroundColorAttributeName : [UIColor whiteColor]};
        [_segment setTitleTextAttributes:selctedTextAttributes forState:UIControlStateSelected];
    }
    return _segment;
}

- (instancetype)initWithFrame:(CGRect)frame{
    if (self == [super initWithFrame:frame]) {
        [self addSubview:self.segment];
        [self ViemFrame];
    }
    return self;
}
- (void)ViemFrame{
//    [self.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    _ComView = [[CommonalityView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 300) Sting:@"1"];
    _PerView = [[PersonageView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 300) Sting:@"2"];
    [self addSubview:self.PerView];
    [self addSubview:self.ComView];
    [_segment mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self);
        make.bottom.equalTo(self);
        make.width.equalTo(@(120));
        make.height.equalTo(@(33));
    }];
    [_ComView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self);
        make.top.equalTo(self);
        make.right.equalTo(self);
        make.bottom.equalTo(self.segment.mas_top).offset(-5);
    }];
    [_PerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self);
        make.top.equalTo(self);
        make.right.equalTo(self);
        make.bottom.equalTo(self.segment.mas_top).offset(-5);
    }];
}
- (void)selectItem:(UISegmentedControl *)sender {
    if (sender.selectedSegmentIndex == 0) {
//        [self ViemFrame];
        [self.ComView.leftView LoadData];
        //第一个界面
//        [self addSubview:self.ComView];
        self.PerView.hidden = YES;
        self.ComView.hidden = NO;
//        [self.PerView removeFromSuperview];
    } else {
        self.ComView.hidden = YES;
        self.PerView.hidden = NO;
        [self.PerView.leftView LoadData];
//        [self addSubview:self.PerView];
//        [self.ComView removeFromSuperview];
    }
}
@end
